import torch
from torch import nn
from fastNLP import Vocabulary

def load_senna_embedding():
    vocab = Vocabulary(padding=None, unknown=None)
    
    with open(
        "/home/wangxiaoli/datasets/embeddings/senna_embeddings/words.lst", "r"
    ) as f:
        words = f.readlines()
        words = [word.strip() for word in words]
        vocab.add_word_lst(words)

    embedding = nn.Embedding(len(vocab), 50)

    with open(
        "/home/wangxiaoli/datasets/embeddings/senna_embeddings/embeddings.txt", "r"
    ) as f:
        embeddings = f.readlines()
        embeddings = [embedding.split() for embedding in embeddings]
        embeddings = [[float(num) for num in embedding] for embedding in embeddings]
        embeddings = torch.tensor(embeddings)
        embedding.weight.data.copy_(embeddings)
    return embedding